<?php

/**
 * This is the model class for table "tracking_task".
 *
 * The followings are the available columns in table 'tracking_task':
 * @property string $id_tracking_task
 * @property integer $id_tracking
 * @property integer $id_task
 * @property string $id_by_matter
 */
class TrackingTask extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return TrackingTask the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tracking_task';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_tracking, id_task', 'required'),
			array('id_tracking, id_task', 'numerical', 'integerOnly'=>true),
			array('id_by_matter', 'length', 'max'=>20),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_tracking_task, id_tracking, id_task, id_by_matter', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
            'track' => array(self::BELONGS_TO, 'Tracking', 'id_tracking')
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_tracking_task' => 'Id Tracking Task',
			'id_tracking' => 'Id Tracking',
			'id_task' => 'Id Task',
			'id_by_matter' => 'Id By Matter',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id_tracking_task',$this->id_tracking_task,true);
		$criteria->compare('id_tracking',$this->id_tracking);
		$criteria->compare('id_task',$this->id_task);
		$criteria->compare('id_by_matter',$this->id_by_matter,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

    public static function getListMatterTask($idTracking, $returnArray = false){
        $criteria=new CDbCriteria;
        $criteria->addCondition('id_tracking = :id_tracking');
        $criteria->params = array(':id_tracking' => (int)$idTracking);

        $model = self::model()->findAll($criteria);
        $result = array();
        if ($model) {
            foreach ($model as $value) {
                $result[] = $value->id_by_matter;
            }
        }
        if($returnArray===true){
            return$result;
        }
        return implode('<br>', $result);
    }
}